﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    public class AttendanceDefined
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllList(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.FPositionNo, a.FDeptNo, a.FEntityNo, a.FEmplNo, b.FEmpName, b.FSeq from t_HREmplPosition a, t_HREmpl b ");
            strSql.Append(" where a.FEmplNo = b.FEmplNo AND a.FEntityNo=@FEntityNo AND FIsMainPosition='Y' AND FEmpStatus <> '99' ");
            strSql.Append(" order by FSeq asc");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        public DataSet GetAllListWithOutIsMainPosition(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.FPositionNo, a.FDeptNo, a.FEntityNo, a.FEmplNo, b.FEmpName, b.FSeq from t_HREmplPosition a, t_HREmpl b ");
            strSql.Append(" where a.FEmplNo = b.FEmplNo AND a.FEntityNo=@FEntityNo  AND FEmpStatus <> '99' ");
            strSql.Append(" order by FSeq asc");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 需要网上考勤的人员名单
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataSet GetListByEntityNo(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.* from v_HRDeptEmpl a,dbo.t_HRDept b");
            strSql.Append(" WHERE a.FDeptNo=b.FDeptNo AND  a.FEntityNo=@FEntityNo and FIsMainPosition='Y'  ");
            strSql.Append("  and FIsAttendance='Y' AND FEmpStatus <> '99' AND FIsAgency='N'");
            strSql.Append("  order by a.FDeptNo,a.FSeq,FDutyNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 
        /// </summary>
        public void UpdataEmpl(List<Model.HREmpl> emplModelList) 
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            if (emplModelList.Count > 0) 
            {
                strSql.Append(" update t_HREmpl set");
                strSql.Append(" FIsAttendance=@FIsAttendance");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");

                foreach (Model.HREmpl model in emplModelList)
                {
                    
                    cmds = new CommandInfo();

                    SqlParameter[] parameters = {
                        new SqlParameter("@FIsAttendance", SqlDbType.NVarChar,1),
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    parameters[0].Value = model.FIsAttendance;
                    parameters[1].Value = model.FEntityNo;
                    parameters[2].Value = model.FEmplNo;
                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }
            }
            if (cmdList.Count > 0) 
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }
        public void UpdataEmplFIsAllowLookFtp(List<Model.HREmpl> emplModelList)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            if (emplModelList.Count > 0)
            {
                strSql.Append(" update t_HREmpl set");
                strSql.Append(" FIsAllowLookFtp=@FIsAllowLookFtp");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");

                foreach (Model.HREmpl model in emplModelList)
                {

                    cmds = new CommandInfo();

                    SqlParameter[] parameters = {
                        new SqlParameter("@FIsAllowLookFtp", SqlDbType.NVarChar,1),
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    parameters[0].Value = model.FIsAllowLookFtp;
                    parameters[1].Value = model.FEntityNo;
                    parameters[2].Value = model.FEmplNo;
                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }
            }
            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

    }
}
